<?php
// $Id$

/**
 * Controller_Party 控制器
 */
class Controller_Party extends Controller_Abstract
{

	function actionIndex()
	{
        // 为 $this->_view 指定的值将会传递数据到视图中
		# $this->_view['text'] = 'Hello!';
	}
	
	function actionList(){
		// 分页查询
		$page = intval($this->_context->page);
		if ($page < 1) $page = 1;
		// 构造查询对象
/*		$select = $partys = Party::find(" status IN ('1','5') ")->Order(' act_id DESC')->limitPage($page,10);
		// 将分页信息和查询到的数据传递到视图
		$this->_view['pagination'] = $select->getPagination();
		$partys = $select->getAll();
		foreach ($partys as $v){ $number[] = $v->act_id; }
		$number = implode(',', $number);
		
		$table = new QDB_Table(array('name'=>'activity'));
		$this->_view['partys'] = $table->select(' act_id IN ( '.$number.' )')->getAll();
*/
		$table = new QDB_Table(array('name'=>'activity'));
		$select = $this->_view['partys'] = $table->select(" status IN ('1','5') ")->Order(' act_id DESC')->limitPage($page,10);
		$this->_view['pagination'] = $select->getPagination();
		$this->_view['partys'] = $select->getAll();
		//dump($this->_view['partys']);
		
	}//END actionList
	
	
	function actionView(){
		$partyBase = Party::find(" status IN ('1','5') AND act_id = ? ", $this->_context->pid)->getOne();
		if ($partyBase->act_id){
			$partyMetas = PartyOptions::find(' oj_id = ? ', $partyBase->act_id)->getAll();
			
			$this->_view['party']['status'] = $partyBase['status'];
			$this->_view['party']['workers'] = 0;
			foreach ($partyMetas as $v){
				//echo $v->oj_value;
				if(  preg_match('/^actWorkerDuty.*/', $v->oj_name, $matches) )
					$this->_view['party']['workers']++;
				
				if ( in_array($v->oj_name, array('actContent', 'actPlan')) )
					$this->_view['party'][$v->oj_name] = nl2br( preg_replace("/ /",'&nbsp;', $v->oj_value) );
				else 
					$this->_view['party'][$v->oj_name] = $v->oj_value;
			}
		}
		//dump( $this->_view['party'] );	
	}//END actionView
}//END Controller